home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / canvas.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-12-02  |  8.9 KB  |  250 lines

  1. /*
  2.  For general Scribus (>=1.3.2) copyright and licensing information please refer
  3.  to the COPYING file provided with the program. Following this notice may exist
  4.  a copyright and/or license notice that predates the release of Scribus 1.3.2
  5.  for which a new license (GPL+exception) is in place.
  6.  */
  7. /***************************************************************************
  8. scribusview.h  -  description
  9. -------------------
  10.     begin                : Fre Apr  6 21:47:55 CEST 2001
  11.     copyright            : (C) 2001 by Franz Schmid
  12.     email                : Franz.Schmid@altmuehlnet.de
  13.     ***************************************************************************/
  14.  
  15. /***************************************************************************
  16. *                                                                         *
  17. *   This program is free software; you can redistribute it and/or modify  *
  18. *   it under the terms of the GNU General Public License as published by  *
  19. *   the Free Software Foundation; either version 2 of the License, or     *
  20. *   (at your option) any later version.                                   *
  21. *                                                                         *
  22. ***************************************************************************/
  23.  
  24. #ifndef CANVAS_H
  25. #define CANVAS_H
  26.  
  27. #include <QApplication>
  28. //#include <QDebug>
  29. #include <QPolygon>
  30. #include <QRect>
  31. #include <QWidget>
  32.  
  33. #include "scribusapi.h"
  34.  
  35. #include "commonstrings.h"
  36. #include "fpoint.h"
  37. #include "fpointarray.h"
  38. #include "pageitempointer.h"
  39.  
  40.  
  41. class Page;
  42. class PageItem;
  43. class ScPainter;
  44. class ScribusDoc;
  45. class ScribusView;
  46.  
  47. struct CanvasViewMode
  48. {
  49.     void init();
  50.     
  51.     double scale;
  52.  
  53.     bool previewMode;
  54.     bool viewAsPreview;
  55.     int previewVisual;
  56.  
  57.     bool m_MouseButtonPressed;
  58.     bool operItemMoving;
  59.     bool operItemResizing;
  60.     bool operItemSelecting;
  61.     bool operTextSelecting;
  62.     QPolygon redrawPolygon;
  63.     QList<PageItemPointer> linkedFramesToShow;
  64.     
  65.     /** if true, selected objects will not be drawn by drawContents() */
  66.     bool drawSelectedItemsWithControls;
  67.     /** if true, drawContents() will draw framelinks even if View->Show Framelinks is false */
  68.     bool drawFramelinksWithContents;
  69.     
  70.     // used for buffering:
  71.     bool forceRedraw;
  72. };
  73.  
  74. QDataStream &operator<<(QDataStream & ds, const CanvasViewMode & vm);
  75. QDataStream &operator>>(QDataStream & ds, CanvasViewMode & vm);
  76.  
  77.  
  78. class SCRIBUS_API Canvas : public QWidget
  79. {
  80.     Q_OBJECT
  81.     
  82. public:    
  83.     static const uint moveWithFullOutlinesThreshold = 21;
  84.     static const uint moveWithBoxesOnlyThreshold = 41;
  85.  
  86.     Canvas(ScribusDoc* doc, ScribusView* parent);
  87.     
  88.     friend class ScribusView; // for now...
  89.     friend class CanvasMode;
  90.     friend class LegacyMode;
  91.     friend class CanvasMode_CopyProperties;
  92.     friend class CanvasMode_Edit;
  93.     friend class CanvasMode_EditGradient;
  94.     friend class CanvasMode_EyeDropper;
  95.     friend class CanvasMode_FrameLinks;
  96.     friend class CanvasMode_Magnifier;
  97.     friend class CanvasMode_NodeEdit;
  98.     friend class CanvasMode_ObjImport;
  99.     friend class CanvasMode_Panning;
  100.     friend class CanvasMode_Normal;
  101.     friend class CanvasMode_Rotate;
  102.     friend class FreehandMode;
  103.     
  104.     /* Dont rely on these codes!
  105.      * 283
  106.      * 7 6
  107.      * 451
  108.      * But always OUTSIDE < 0, INSIDE >= 0 and any specific handle > 0.
  109.      */
  110.     enum FrameHandle { 
  111.         OUTSIDE = -1,
  112.         INSIDE = 0,
  113.         NORTHWEST = 2,
  114.         NORTH = 8,
  115.         NORTHEAST = 3,
  116.         EAST = 6,
  117.         SOUTHEAST = 1,
  118.         SOUTH = 5,
  119.         SOUTHWEST = 4,
  120.         WEST = 7
  121.     };
  122.     
  123.     enum RenderMode {
  124.         RENDER_NORMAL,                // update buffer, paint buffer: expensive for large regions
  125.         RENDER_BUFFERED,              // just paint buffer: fast, but only controls may change (eg. resize mode)
  126.         // in the following two modes, only the selected objects are updated. Might not be exact.
  127.         RENDER_SELECTION_SEPARATE,    // paint buffer w/o selection, then paint selection (eg. img edit, nodeedit, rotate, beziercurve)
  128.         RENDER_SELECTION_BUFFERED,    // paint buffer w/o selection, update selection buffer, then paint selection buffer (eg. move, text edit)
  129.         RENDER_LEGACY
  130.     };
  131.     
  132.     void setRenderMode(RenderMode m);
  133.     
  134.     void clearBuffers();              // very expensive
  135.     
  136.     // deprecated:
  137.     void resetRenderMode() { m_renderMode = RENDER_NORMAL; clearBuffers(); }
  138.     void setRenderModeFillBuffer() { m_renderMode = RENDER_BUFFERED; }
  139.     void setRenderModeUseBuffer(bool use) { m_renderMode = (use ? RENDER_BUFFERED : RENDER_NORMAL) ; }
  140.  
  141.     double scale() const { return m_viewMode.scale; }
  142.     void setScale(double scale) { if (m_viewMode.scale != scale) { m_viewMode.scale = scale; clearBuffers(); update(); } }
  143.     QPoint canvasToLocal(FPoint p) const;
  144.     QPoint canvasToGlobal(FPoint p) const;
  145.     QPoint canvasToLocal(QPointF p) const;
  146.     QPoint canvasToGlobal(QPointF p) const;
  147.     QRect canvasToLocal(QRectF p) const;
  148.     QRect canvasToGlobal(QRectF p) const;
  149.     FPoint localToCanvas(QPoint p) const;
  150. //    FPoint localToCanvas(QPointF p) const;
  151.     FPoint globalToCanvas(QPoint p) const;
  152. //    FPoint globalToCanvas(QPointF p) const;
  153.     QRectF globalToCanvas(QRect p) const;
  154. //    QRectF globalToCanvas(QRectF p) const;
  155.     bool hitsCanvasPoint(QPoint globalPoint, FPoint canvasPoint) const;
  156.     bool hitsCanvasPoint(QPoint globalPoint, QPointF canvasPoint) const;
  157.     QRect exposedRect()const;
  158.     /** Returns the framehandle or INSIDE if the position falls into the frame. */
  159.     FrameHandle frameHitTest(QPointF canvasPoint, PageItem* frame) const;
  160.     FrameHandle frameHitTest(QPointF point, QRectF frame) const;
  161.     /**
  162.         Returns the item under the cursor or NULL if none found.
  163.      Does *not* change the selection.
  164.      If itemAbove is given, it will look for an item under itemAbove, allowing select under.
  165.      The flag 'allowInGroup' controls if single items within a group or only whole groups are considered.
  166.      The flag 'allowMasterItems' controls if items from a masterpage are considered.
  167.      (this flag is ignored in masterpage mode, since all items are masterpage items then).
  168.      */
  169.     PageItem* itemUnderCursor(QPoint globalPos, PageItem* itemAbove=NULL, bool allowInGroup=false, bool allowMasterItems=false) const;
  170.     
  171.     PageItem* itemUnderItem(PageItem* item, int& index) const;
  172.     
  173.     const QPolygon& redrawPolygon() const { return m_viewMode.redrawPolygon; }
  174.     QPolygon& newRedrawPolygon() 
  175.     {
  176.         m_viewMode.redrawPolygon.clear();
  177.         return m_viewMode.redrawPolygon;
  178.     }
  179.     void setPreviewMode(bool on) { m_viewMode.previewMode = on; }
  180.     bool isPreviewMode() const { return m_viewMode.previewMode || m_viewMode.viewAsPreview; }
  181.     bool usePreviewVisual() const { return m_viewMode.viewAsPreview && m_viewMode.previewVisual != 0; }
  182.     int previewVisual() const { return m_viewMode.previewVisual; }
  183.     void setPreviewVisual(int mode) { m_viewMode.previewVisual = qMax(0, mode); m_viewMode.viewAsPreview = (mode >= 0); }
  184.     
  185.     void DrawMasterItems(ScPainter *painter, Page *page, QRect clip);
  186.     void DrawPageItems(ScPainter *painter, QRect clip);
  187.     virtual void paintEvent ( QPaintEvent * p );
  188.     void displayXYHUD(QPoint m);
  189.     void displayCorrectedXYHUD(QPoint m, double x, double y);
  190.     void displayCorrectedSingleHUD(QPoint m, double val, bool isX);
  191.     void displayXYHUD(QPoint m, double x, double y);
  192.     void displaySizeHUD(QPoint m, double x, double y, bool isLine = false);
  193.     void displayRotHUD(QPoint m, double rot);
  194.     
  195.     void setupEditHRuler(PageItem * item, bool forceAndReset = false);
  196.     
  197. private:
  198.     void DrawPageMarks(ScPainter *p, Page* page, QRect clip);
  199.     void drawLinkFrameLine(ScPainter* painter, FPoint &start, FPoint &end);
  200.     void PaintSizeRect(QRect neu);
  201.     void PaintSizeRect(QPolygon neu);
  202.     void Transform(PageItem *currItem, QPainter *p);
  203.     void Transform(PageItem *currItem, QMatrix& m);
  204.     void TransformM(PageItem *currItem, QPainter *p);
  205.     void getGroupRectScreen(double *x, double *y, double *w, double *h);
  206.  
  207.     /**
  208.         Enlarges the buffer such that it contains the viewport.
  209.      */
  210.     bool adjustBuffer();
  211.     /**
  212.         Fills the given buffer with contents.
  213.         bufferOrigin and clipRect are in local coordinates
  214.      */
  215.     void fillBuffer(QPaintDevice* buffer, QPoint bufferOrigin, QRect clipRect);
  216.     void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
  217.     void drawBackgroundMasterpage(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
  218.     void drawBackgroundPageOutlines(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
  219.     void drawGuides(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
  220.     void drawFrameLinks(ScPainter* painter);
  221.     void drawControls(QPainter* p);
  222.     void drawControlsMovingItemsRect(QPainter* pp);
  223. //    void drawControlsHighlightRect(QPainter* pp);
  224.     void drawControlsGradientVectors(QPainter* psx, PageItem *currItem);
  225.     void drawControlsBezierCurve(QPainter* pp, PageItem* currItem);
  226.     void drawControlsMeasurementLine(QPainter* pp);
  227.     void drawControlsDrawLine(QPainter* pp);
  228.     void drawControlsFreehandLine(QPainter* pp);
  229.     void getClipPathForPages(FPointArray* PoLine);
  230.     void calculateFrameLinkPoints(PageItem* pi1, PageItem* pi2, FPoint& start, FPoint& end);
  231.         
  232. private:
  233.     ScribusDoc* m_doc;
  234.     ScribusView* m_view;
  235.     CanvasViewMode m_viewMode;
  236.     
  237.     RenderMode m_renderMode;
  238.     /*QImage*/QPixmap m_buffer;
  239.     QRect m_bufferRect;
  240.     QPixmap m_selectionBuffer;
  241.     QRect m_selectionRect;
  242.     FPoint m_oldMinCanvasCoordinate;
  243. };
  244.  
  245.  
  246. #endif
  247.  
  248.  
  249.  
  250.